// document.write("<script language=javascript src='../sourceControl/js/jquery.min.js'></script>");
document.write("<script language=javascript src='../sourceControl/js/api.js'></script >");


var siteId = ''

$(function() {
  function GetRequest () {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
      }
    }
    siteId = theRequest.devid
    // return theRequest;
  }
  GetRequest()

	$(".switch_date span").click(function() {
		$(".switch_date span").removeClass("Highlight")
		$(this).addClass("Highlight")
		let higHtml = $(this).html()
		//console.log(higHtml)
		if (higHtml == '天') {
			getData(1)
			JSCBByData(0)
		} else if (higHtml == '周') {
			getData(3)
			JSCBByData(1)
		} else if (higHtml == '月') {
			getData(2)
			JSCBByData(2)
		}
	})

	getData(1)
	JSCBByData(0)
  getSateImg()
function getSateImg(){
  // console.log(getData(2))
  let JSCparam = {
    page:1,
    rows:10,
    siteId: siteId,
    month:'202202'
  }
  JSCBByAjax('GET', api.getStaeImg, JSCparam, function (res) {
      console.log(res)
      var html = ``
      res.list.forEach(item=>{
        html = html +`<div class="img_map">
          <img src="${item.SITE_SATELLTEROCKERIMAGE_URL}" alt="">
          <span>${item.CREATEDATE} 拍摄</span>
        </div>`
      })
    $("#tupian").append(html)

  })
}
	//获取数据,flag  1代表天2代表月3代表周
	function getData(flag) {
		let param = {
			flag: flag,
      siteId: siteId
		}
		staticAjax('GET', api.findStaticData, param, function(res) {
			console.log(res)
			var chart1X = [],
				chart1Y = [],
				chart1Y1 = [];
			if (res.outAndInData.length > 0) {
				for (let i in res.outAndInData) {
					chart1X.push(res.outAndInData[i].flagTime)
					chart1Y.push(res.outAndInData[i].passNum)
					chart1Y1.push(res.outAndInData[i].shotNum)
				}
			}
			getSnapshot(chart1X, chart1Y, chart1Y1)
			var chart2X = [],
				chart2Y = [],
				chart2Y1 = [];
			if (res.gpsData.length > 0) {
				for (let i in res.gpsData) {
					chart2X.push(res.gpsData[i].flagTime)
					chart2Y.push(res.gpsData[i].passNum)
					chart2Y1.push(res.gpsData[i].shotNum)
				}
			}
			getSatellite(chart2X, chart2Y, chart2Y1)
		})
	}

	//获取群众举报数据,type  0代表天1代表月2代表周
	function JSCBByData(type) {
		let JSCparam = {
			type: type,
      siteId: siteId
		}
		JSCBByAjax('GET', api.findJSCBBySiteIdNew, JSCparam, function(res) {
			console.log(res)
			var chart3X = [],
				chart3Y = [];
			if (res.length > 0) {
				for (let i in res) {
					chart3X.push(res[i].TIME)
					chart3Y.push(res[i].COUNT)
				}
			}
			getReportChart(chart3X, chart3Y)
		})
	}

	//报警信息
	let Warningparam = {
    siteId: siteId
	}
	staticAjax('GET', api.earlyWarning, Warningparam, function(res) {
		console.log(res)
		$(".tipinfo").text(res.text)
	})


	//卫星摇感影像
	// let siteparam = {
	// 	buildingSiteNum: 'H_201901162005_20190625_10920'
	// }
	// satelliteAjax('GET', api.getBuildSiteInfo, siteparam, function (res) {
	// 	console.log(res)
	// })

	var pathArr = [
		[116.286439,39.987653],[116.287716,39.987628],[116.287678,39.987003],[116.286208,39.987048],[116.286439,39.987653]
	]
	var points = '116.302269,39.99242'

	var mapTypeJson = {
		enableMapClick: false,
		mapType: BMAP_HYBRID_MAP
	};
	var map = new BMap.Map('mappart', mapTypeJson); // 创建Map实例
	map.centerAndZoom(new BMap.Point(points), 4); //初始化显示级别和位置

	getConstruction(pathArr)
	// 颜色值 {}
	function getConstruction(coordinatesArr) {
		var type = {
			'1': '#D73300',
			'2': '#00DC81',
			'3': '#D98900',
			'4': '#FFF442',
			'5': 'blue',
			'6': 'green'
		}
		var coordinates = coordinatesArr
		var path = []
		coordinates.forEach(item => {
			path = [...path, ...[new BMap.Point(item[0], item[1])]]
		})
		var polygon = new BMap.Polygon(path, {
			strokeColor: type['1'],
			strokeWeight: 4,
			strokeOpacity: 0.5
		});
		map.addOverlay(polygon);

	}

	//出入口抓拍
	function getSnapshot(x, y, y1) {
		var chartDom = document.getElementById('main');
		var myChart = echarts.init(chartDom);
		var option;
		option = {
			tooltip: {
				trigger: 'axis',
				axisPointer: {
					type: 'line'
				}
			},
			title: {
				show: true,
				textStyle: {
					fontWeight: "normal",
					color: "#fff",
					fontSize: 14
				},
				left: "center"
			},
			legend: {
				textStyle: {
					color: '#fft'
				}
			},
			grid: {
				left: '3%',
				right: '4%',
				bottom: '3%',
				containLabel: true
			},
			yAxis: {
				type: 'value',
				axisLine: {
					lineStyle: { //改变xy轴线条的颜色
						color: "#FFF",
						width: 1 //这里是为了突出显示加上的
					}
				},
			},
			xAxis: {
				type: 'category',
				data: x,
				axisLabel: {
					textStyle: { //改变xy轴上文字的颜色
						color: "#FFF"
					}
				},
			},
			series: [{
					name: '车辆数',
					type: 'bar',
					stack: 'total',
					barWidth: 30,
					label: {
						show: true
					},
					emphasis: {
						focus: 'series'
					},
					data: y
				},
				{
					name: '抓拍数',
					type: 'line',
					stack: 'total',
					emphasis: {
						focus: 'series'
					},
					barWidth: 30,
					data: y1
				}

			]
		};
		option && myChart.setOption(option);
		myChart.on('click', function (params) {
			console.log(params.name)
      // window.location.href = '/ditu/sourceControl/details.html?date=' + params.name + '&devid='+siteId
      layui.use('layer', function () {
        var layer = layui.layer;
        layer.open({
          type: 2,
          fixed: true,
          title: ['详情', 'font-size: 22px;color: rgb(49, 70, 89);'],
          closeBtn: 1,
          scrollbar: false,
          maxmin: false,
          content: '/ditu/sourceControl/details.html?date=' + params.name + '&devid=' + siteId,
          area: ['100%', '100%'],
          end: function () {
            // 暂时不用
          }
        });
      });
		})
	}

	// 卫星定位研判
	function getSatellite(x, y, y1) {
		var chartDom = document.getElementById('satellite');
		var myChart = echarts.init(chartDom);
		var option;
		option = {
			tooltip: {
				trigger: 'axis',
				axisPointer: {
					type: 'line' // 'shadow' as default; can also be 'line' or 'shadow'
				}
			},
			legend: {
				textStyle: {
					color: '#fft'
				}
			},
			grid: {
				left: '3%',
				right: '4%',
				bottom: '3%',
				containLabel: true
			},
			yAxis: {
				type: 'value',
				axisLabel: {
					textStyle: { //改变xy轴上文字的颜色
						color: "#FFF"
					}
				},

			},
			xAxis: {
				type: 'category',
				data: x,
				axisLabel: {
					textStyle: { //改变xy轴上文字的颜色
						color: "#FFF"
					}
				},
			},
			series: [{
					name: '车辆数',
					type: 'bar',
					stack: 'total',
					barWidth: 30,
					label: {
						show: true
					},
					itemStyle: {
						color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: '#83bff6'
							},
							{
								offset: 0.5,
								color: '#188df0'
							},
							{
								offset: 1,
								color: '#188df0'
							}
						])
					},
					emphasis: {
						focus: 'series'
					},
					data: y
				},
				{
					name: '抓拍数',
					type: 'line',
					stack: 'total',
					label: {
						show: true
					},
					emphasis: {
						focus: 'series'
					},
					barWidth: 30,
					data: y1
				}
			]
		};
		option && myChart.setOption(option);
		myChart.on('click', function (params) {
			console.log(params.name)
			// window.location.href = 'details.html?date='+params.name+''
      
		})
	}

	// 群众举报
	function getReportChart(x, y) {
		var chartDom = document.getElementById('reportChart');
		var myChart = echarts.init(chartDom);
		var option;
		option = {
			tooltip: {
				trigger: 'axis',

			},
			grid: {
				left: '3%',
				right: '4%',
				bottom: '3%',
				containLabel: true
			},
			legend: {
				textStyle: {
					color: '#fft'
				}
			},
			xAxis: {
				type: 'category',
				boundaryGap: false,
				data: x,
				axisLabel: {
					textStyle: { //改变xy轴上文字的颜色
						color: "#FFF"
					}
				},
			},
			yAxis: {
				type: 'value',
				axisLabel: {
					textStyle: { //改变xy轴上文字的颜色
						color: "#FFF"
					}
				},
			},
			series: [{
				name: '举报数',
				data: y,
				type: 'line',
				areaStyle: {}
			}]
		};

		option && myChart.setOption(option);
	}
	// 弹框layui
	function Spring(src, arr) {
		console.log(src, arr)
		// let html = $("#tupian").prop("outerHTML")
		layui.use('layer', function() {
			var layer = layui.layer;
			layer.open({
				type: 1,
				fixed: true,
				content: `<div style="width:600px;hight:400px;"><img style="width:100%;hight:100%;" src="${src}" alt=""></div>`,
				btnAlign: 'c', //按钮居中
				shade: 0.2, //不显示遮罩
				area: ['600px', '600px'],
				title: false

			})
		})
	}

})

